package cn.stylefeng.guns.modular.rest.bh;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.replenishment.entity.ReplenishmentOrder;
import cn.stylefeng.guns.modular.replenishment.model.params.ReplenishmentOrderParam;
import cn.stylefeng.guns.modular.replenishment.model.result.ReplenishmentOrderResult;
import cn.stylefeng.guns.modular.replenishment.service.ReplenishmentOrderService;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.modular.scheduleInfo.entity.ScheduleInfo;
import cn.stylefeng.guns.modular.scheduleInfo.model.params.ScheduleDetailInfoParam;
import cn.stylefeng.guns.modular.scheduleInfo.model.params.ScheduleInfoParam;
import cn.stylefeng.guns.modular.scheduleInfo.model.params.ScheduleInfoPlantParam;
import cn.stylefeng.guns.modular.scheduleInfo.model.result.ScheduleDetailInfoResult;
import cn.stylefeng.guns.modular.scheduleInfo.model.result.ScheduleDetailInfoResultNew;
import cn.stylefeng.guns.modular.scheduleInfo.model.result.ScheduleInfoResult;
import cn.stylefeng.guns.modular.scheduleInfo.service.ScheduleDetailInfoService;
import cn.stylefeng.guns.modular.scheduleInfo.service.ScheduleInfoService;
import cn.stylefeng.guns.sys.modular.system.entity.Dept;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.DeptService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.Duration;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 补货
 * 主要用于补货的列表展示
 * @author wp
 * @date 2025-03-22
 */
@Controller
@RequestMapping("/rest/bh")
public class restBhController extends BaseController {

    @Autowired
    private UserAop userAop;
    @Autowired
    private DeptService deptService;

    @Autowired
    private ReplenishmentOrderService replenishmentOrderService;
    /**
     * 补货列表
     * @param replenishmentOrderParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/bhList")
    public ResponseData list(ReplenishmentOrderParam replenishmentOrderParam, String condition) {
        User user = userAop.getUser();
        Long deptId = user.getDeptId();
        replenishmentOrderParam.setStatus("待补货");
        replenishmentOrderParam.setGoodsCustomerId(deptId);
        List<ReplenishmentOrderResult> listBySpec = replenishmentOrderService.findListBySpec(replenishmentOrderParam);

        return ResponseData.success(listBySpec);
    }


    /**
     * 根据ID获取补货单信息
     * @param replenishmentOrderParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/getById")
    public ResponseData getById(ReplenishmentOrderParam replenishmentOrderParam) {
        ReplenishmentOrder replenishmentOrder = replenishmentOrderService.getById(replenishmentOrderParam.getId());
        return ResponseData.success(replenishmentOrder);
    }

    /**
     * 补货完成
     * @param updateReplenish
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateReplenish")
    public ResponseData updateReplenish(UpdateReplenishIby updateReplenish) {
        if(ToolUtil.isNotEmpty(updateReplenish.getId())){
            replenishmentOrderService.lambdaUpdate()
                    .set(ReplenishmentOrder::getStatus,"已完成")
                    .eq(ReplenishmentOrder::getId,updateReplenish.getId())
                    .update();
        }
        return ResponseData.success();
    }


}
